package cn.liuweiwei.util;


public class Result {

    private static final Integer SUCCESS = 0; 
    private static final Integer ERROR = 1;

    private Integer status;
    private String msg;
    private Object data;

    @Deprecated
    private Integer code;

    private Result(Integer status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static Result success(String message) {
        return new Result(SUCCESS, message, null);
    }

    public static Result error(String message) {
        return new Result(ERROR, message, null);
    }

    public static Result successWithObj(Object object) {
        return new Result(SUCCESS, null, object);
    }

    public static Result successWithCodeAndObj(Object object) {
        Result result = new Result(SUCCESS, null, null);
        result.setCode(SUCCESS);
        result.setData(object);
        return result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    private void setMsg(String msg) {
        this.msg = msg;
    }

    private void setData(Object data) {
        this.data = data;
    }

    public Integer getStatus() {
        return status;
    }

    public String getMsg() {
        return msg;
    }

    public Object getData() {
        return data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                ", code=" + code +
                '}';
    }
}
